package com.dongdongshop.service.impl;

import com.dongdongshop.mapper.TbItemMapper;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbItemExample;
import com.dongdongshop.service.TbItemServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class TbItemServiceImpl implements TbItemServiceI {

    @Autowired
    private TbItemMapper tbItemMapper;

    @Override
    public List<TbItem> selectItemList(Long id) {
        TbItemExample example = new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(id);//根据goodsId查询（spu的Id）
        criteria.andStatusEqualTo("2");//查询正常状态商品
        example.setOrderByClause("is_default desc");//按照是否默认排序，保证默认的数据在第一个
        return tbItemMapper.selectByExample(example);
    }

    @Override
    public TbItem selectItemById(Long itemId) {
        return tbItemMapper.selectByPrimaryKey(itemId);
    }

    @Override
    public List<TbItem> selectItemByGoodsId(Long goodsId) {
        TbItemExample example = new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andGoodsIdEqualTo(goodsId);
        List<TbItem> items = tbItemMapper.selectByExample(example);
        return items;
    }
}
